package com.llly.controller;


import com.github.pagehelper.Page;
import com.llly.pojo.Easybuy_order;
import com.llly.pojo.Easybuy_user;
import com.llly.service.NewsService;
import com.llly.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userservice;

    @Autowired
    private NewsService newsService;


    //登录
    @RequestMapping("/login")
    public Easybuy_user login(@RequestParam String loginName , @RequestParam String password){
        Easybuy_user loing = userservice.loing(loginName, password);
        return loing;
    }
    //注册新用户，（共用）管理页面，新增用户
    @PostMapping("/adduser")
    public int adduser(@RequestBody Easybuy_user ea){
        return userservice.AddEasybuy_user(ea);
    }

    //id查询，查看用户详情
    @RequestMapping("/iddetails")
    public Easybuy_user iddetails(@RequestParam Integer id){
        Easybuy_user iddetails = userservice.iddetails(id);
        return iddetails;
    }
    //管理页面，修改
    @PostMapping("/updateUser.do")
    public int updateUser(@RequestBody Easybuy_user ea){
        int i = userservice.updateUser(ea);
        return i;
    }

    //查看用户信息
    @RequestMapping("/showUsers")
    public Map<String,Object> showUsers(@RequestParam Integer PageIndex){
        Page<Easybuy_user> easybuy_users = userservice.showUsers(PageIndex);
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("Result",easybuy_users.getResult());
        map.put("Total",easybuy_users.getTotal());
        map.put("PageNum",easybuy_users.getPageNum());
        map.put("Pages",easybuy_users.getPages());
        return map;
    }
    //删除用户信息
    @RequestMapping("/deleteUsers")
    public int deleteUsers(@RequestParam Integer id){
        int i = userservice.deleteUsers(id);
        return i;
    }
}
